package main

import (
	"fmt"

	"github.com/kataras/iris/v12"
)

func main() {
	fmt.Println("hello")
	app := iris.New()

	app.PartyFunc("/users", func(users iris.Party) {
		users.Use(myAuthMiddlewareHandler)

		// http://localhost:8080/users/42/profile
		users.Get("/{id:int}/profile", userProfileHandler)
		// http://localhost:8080/users/messages/1
		users.Get("/messages/{id:int}", userMessageHandler)
	})

	// 开始运行监听的ip:端口
	app.Run(iris.Addr(":9321"))
}

func myAuthMiddlewareHandler(ctx iris.Context) {
	ctx.JSON(iris.Map{"message": "Hello Iris!"})
}

func userProfileHandler(ctx iris.Context) {
	userID, _ := ctx.Params().GetUint64("id")
	ctx.Writef("User profile ID: %d", userID)
}

func userMessageHandler(ctx iris.Context) {
	userID, _ := ctx.Params().GetUint64("id")
	ctx.Writef("User messages ID: %d", userID)
}
